<?

if (!(isset($DATA['mainmenu']) && is_array($DATA['mainmenu']) && sizeof($DATA['mainmenu']))) return 1;

if (!function_exists('basicMainMenuShow')) {
	function basicMainMenuShow($_menu, $levels, $current, $filter, $lang = '') {
		global $CURRENT;
		$_filter = is_array($filter) ? (int)array_shift($filter) : $filter;

		foreach($_menu as $id => $v) {
			if (($v['tag'] & $_filter) != $_filter) continue;
			
			$class = array("level$current", $v['first'], $v['last']);
			
			if (stack('makeIds', false)) $class[] = "item$id";
			if ($p = inCrumb($id)) $class[] = "incrumb$current";
			if (sizeof($v['data'])) $class[] = "sub$current";

			$url = $lang.$CURRENT->getAliasById($id);
			$name = $v['localname'] ? $v['localname'] : $v['name'];
			

			?><li class="<?=implode(' ', array_trim_empty($class))?>"><?
			
				if ($p && $p['last']) { 
					?><strong class="level<?=$current?>"><span><?=t($name, 'menu')?></span></strong><?
				} else { 
					?><a href="<?=$url?>" title="<?=ht($name, 'menu')?>" class="level<?=$current?>"><span><?=t($name, 'menu')?></span></a><?
				} 

				if (($levels > $current) && ($_menu2 = $v['data'])) { 

					?><ul class="level<?=$current + 1?>"><? basicMainMenuShow($_menu2, $levels, $current + 1, $filter, $lang); ?></ul><?
				}
	
			?></li><?
		}
	}
}

$_menu = $DATA['mainmenu'];

if ($_parent = (int)stack('parent')) {
	$_lookfor = create_function('$menu, $parent, $_lookfor', 
		'$res = array(); 
			foreach ($menu as $id => $v) if ($v["parent"] == $parent) $res[$id] = $v;
			if (sizeof($res)) return $res;
			foreach ($menu as $id => $v)
				if (isset($v["data"]) && is_array($res = $_lookfor($v["data"], $parent, $_lookfor)))
					return $res;
			return false;
		');
	if (!($_menu = $_lookfor($_menu, $_parent, $_lookfor))) return false;
}

if (is_array($_menu) && sizeof($_menu))
	basicMainMenuShow($_menu, stack('levels', 1), 1, stack('filter', 0), $DATA['mainmenu-lang']);

unstack();